package src.leetcode.greedy.medium_0045;

public class jump {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.jump(new int[]{1,2,3}));
    }
}

class Solution {
    public int jump(int[] nums) {
        if(nums.length < 2) return 0;
        int step = 1;
        int furthest = nums[0];
        int lastfurthest = 0;

        while (furthest < nums.length - 1){
            int temp = furthest;
            for (int i = lastfurthest; i <= temp; i++){
                furthest = Math.max(furthest, i + nums[i]);
            }
            lastfurthest = temp;
            step++;
        }

        return step;
    }
}
